load("@rules_pkg//pkg:mappings.bzl", "pkg_attributes", "pkg_filegroup", "pkg_files", "pkg_mklink")
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")

pkg_files(
    name = "protobuf_bin",
    srcs = ["@protobuf//:protoc"],
    attributes = pkg_attributes(
        mode = "0755",
    ),
    prefix = "bin",
    tags = ["manual"],
)

pkg_files(
    name = "protobuf_lib",
    srcs = ["@protobuf//:protoc_lib"],
    excludes = ["libprotoc_lib.a"],
    tags = ["manual"],
)

# Workaround as long as we do not build the python wheel with Bazel (CMK-14608)
pkg_mklink(
    name = "protobuf_lib_link",
    link_name = "libprotobuf.so.31",
    tags = ["manual"],
    target = "libprotoc_lib.so",
)

pkg_files(
    name = "well_known_proto_files",
    srcs = ["@protobuf//:well_known_type_protos"],
    tags = ["manual"],
)

pkg_filegroup(
    name = "well_known_protos",
    srcs = [
        ":well_known_proto_files",
    ],
    prefix = "include/google/protobuf",
    tags = ["manual"],
)

pkg_filegroup(
    name = "protobuf_library",
    srcs = [
        ":protobuf_lib",
        ":protobuf_lib_link",
    ],
    prefix = "lib",
    tags = ["manual"],
)

pkg_filegroup(
    name = "protobuf",
    srcs = [
        ":protobuf_bin",
        ":protobuf_library",
        ":well_known_protos",
    ],
    tags = ["manual"],
    visibility = ["//omd:__pkg__"],
)

pkg_tar(
    name = "protobuf_tar",
    srcs = [":protobuf"],
    package_file_name = "protobuf.tar",
    tags = ["manual"],
    visibility = ["//omd:__pkg__"],
)
